// 自定义验证邮箱方法
// const checkEmail = (rule: any, value: any, callback: any) => {
//     if (!value) callback(new Error('Please input the email'))
//     const regExp = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(com|cn|net)$/
//     regExp.test(value) ? callback() : callback(new Error('Please input the correct email address'))
// }

import { ProductService } from '@/api/product'
import { InferService } from '@/api/infer'
import { EnvironmentService } from '@/api/environment'
import { ModelService } from '@/api/model'

let productList = null
let inferList = null
let environmentList = null
let modelList = null

const getLists = async () => {
    let res = await ProductService.getProducts();
    productList = res.data
    res = await InferService.getInfers();
    inferList = res.data
    res = await EnvironmentService.getEnvironments();
    environmentList = res.data
    res = await ModelService.getModels();
    modelList = res.data
}

await getLists()

export const taskForm = {
    base: [
        { 
            label: '测试目的', 
            field:'test_purpose', 
            type: 'textarea', 
            labelWidth: '80px', 
            placeholder: '示例：测试大小模型的精度差异', 
            //rules: [{ required: true, message: '请填写测试目的'}] 
        },
        { 
            label: '预期结果', 
            field:'expected_result', 
            type: 'textarea', 
            labelWidth: '80px', 
            placeholder: '示例：大模型精度明显优于小模型', 
            //rules: [{ required: true, message: '请填写预期结果'}]
        },
        { 
            label: '产品', 
            field:'product_name', 
            type: 'select',
            labelWidth: '200px',
            options: {
                labelkey: 'product_name',
                valueKey: 'product_name',
                data: productList
            },
            //rules: [{ required: true, message: '请选择测试产品'}] ,
        },
        { 
            label: '环境', 
            field:'test_environment', 
            type: 'select',
            options: {
                labelkey: 'test_environment',
                valueKey: 'test_environment',
                data: environmentList
            },
            //rules: [{ required: true, message: '请选择测试环境'}] ,
        },
        { 
            label: '推理', 
            field:'test_infer', 
            type: 'select',
            options: {
                labelkey: 'test_infer',
                valueKey: 'test_infer',
                data: inferList
            },
            //rules: [{ required: true, message: '请选择测试推理'}] ,  
        },
        { 
            label: '识别模型', 
            field:'modelnames', 
            type: 'select-multiple',
            clearable: true,
            options: {
                labelkey: 'name',
                valueKey: 'name',
                data: modelList
            },
            //rules: [{ required: true, message: '请选择识别模型'}] , 
        },
        { label: 'svn', field:'svn', type: 'text', placeholder: '示例：1163。如无指定，默认测试最新版本。', },
        { label: '测试集', field:'test_data', type: 'text', placeholder: '示例：/data/public_sharing/czhong/test_imgs。优先存放于公共目录避免无权限。'  },
        { label: '补充说明', field:'remark', type: 'textarea',  placeholder: '要求测试人员需要关注的细节，如开启风扇、模型单独存放于某位置。'},
        { label: '配置文件', field:'file', type: 'upload', rules: [{ required: true, message: '请上传配置文件', trigger: 'change'}], value: '' },
    ]
} as Record<string, Form.FieldItem[]>

const thread_num = [
    { label: '1', value: 1 }, 
    { label: '2', value: 2 }, 
    { label: '3', value: 3 }, 
    { label: '4', value: 4 },
    { label: '5', value: 5 }, 
    { label: '6', value: 6 }, 
    { label: '8', value: 8 }, 
    { label: '10', value: 10 },
    { label: '12', value: 12 }, 
    { label: '16', value: 16 }, 
    { label: '18', value: 18 },
    { label: '20', value: 20 },
    { label: '24', value: 24 },
]

export const testParam = {
    base: [
        { 
            label: '线程数', 
            field: 'instance_num', 
            type: 'checkButton',
            options: {
                data: thread_num
            }
        },
        { 
            label: '样本倍数', 
            field: 'duplicate_num', 
            type: 'inputNumber'
        },
        { 
            label: '循环次数', 
            field: 'loop_num', 
            type: 'inputNumber'
        },
    ]
} as Record<string, Form.FieldItem[]>

// 表单配置示例
// export const exampleForm = {
//     base: [
//         { label: '姓名', field: 'name', disabled: true },
//         { label: '性别', field: 'gender', type: 'radio', options: { data: [{ label: '男', value: 1 }, { label: '女', value: 0 }] } },
//         { label: '爱好', field: 'hobbies', type: 'checkbox', options: { data: [{ label: '吃饭', value: 1 }, { label: '睡觉', value: 2 }, { label: '写代码', value: 3 }] } },
//         { label: '工作', field: 'job', type: 'select', options: { data: [{ label: '吃饭', value: 1 }, { label: '睡觉', value: 2 }, { label: '写代码', value: 3 }] } },
//         { label: '密码', field: 'password', type: 'password', placeholder: '这是一个密码输入框' },
//         { label: '只读', field: 'readonly', readonly: true, placeholder: '这是一个只读输入框' },
//         { label: '留言板', field: 'summary', type: 'textarea', placeholder: '留言板' },
//     ],
//     customkeyForm: [
//         { label: '标题', field: 'name' },
//         { label: '性别', field: 'gender', type: 'radio', options: { labelkey: 'title', valueKey: 'val', data: [{ title: '男', val: 1 }, { title: '女', val: 0 }] } },
//     ],
//     ruleForm: [
//         { label: '姓名', field: 'name', rules: [{ required: true, message: 'name is required' }] },
//         { label: '邮箱', field: 'email', rules: [{ required: true, validator: checkEmail }] },
//     ]
// } as Record<string, Form.FieldItem[]>
